package com.hua.api.modules.express.rest;

import com.hua.api.core.constants.Status;
import com.hua.api.core.framework.annotation.AnonymousAccess;
import com.hua.api.core.framework.annotation.TokenCheck;
import com.hua.api.core.framework.http.response.OpenApiResponse;
import com.hua.api.core.framework.util.Result;
import com.hua.api.core.out.express.imdada.request.CityCodeListRequest;
import com.hua.api.core.out.express.ishansong.request.GetUserAccountRequest;
import com.hua.api.core.out.express.ishansong.request.OpenCitiesListsRequest;
import com.hua.api.core.out.express.ishansong.request.QueryAllStoresRequest;
import com.hua.api.modules.express.service.ExpressOrderService;
import com.hua.api.modules.express.service.ShopInfoExpressService;
import com.hua.api.modules.express.service.dto.ExpressInfoCriteria;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/expressInfo")
public class ExpressInfoController {

    private final ExpressOrderService expressOrderService;
    private final ShopInfoExpressService shopInfoExpressService;

    @AnonymousAccess
    @RequestMapping("/bindShopExpress/{shopId}/{expressCode}")
    public Result bindShopInfoExpress(@PathVariable Integer shopId, @PathVariable String expressCode,String storeId) {
        shopInfoExpressService.bindShopInfoExpress(shopId, expressCode,storeId);
        return Result.success();
    }

    @AnonymousAccess
    @RequestMapping("/test1")
    public ResponseEntity<Map<String,Object>> test1(){
        CityCodeListRequest request = new CityCodeListRequest();
        OpenApiResponse response = request.doRequest();
        Map<String,Object> map = new HashMap<>();
        map.put("data",response.toJSONObject());
        return  new ResponseEntity<>(map,HttpStatus.OK);
    }


    @AnonymousAccess
    @RequestMapping("/queryAllStore/{expressCode}")
    public Result queryAllStore(@PathVariable String expressCode, ExpressInfoCriteria criteria){
        return  Result.of(shopInfoExpressService.queryAllStore(criteria,expressCode));
    }

    //
    @AnonymousAccess
    @RequestMapping("/getUserAccount/{expressCode}")
    @TokenCheck(userAgent = "getUserAccount",source = { Status.admin })
    public Result getUserAccount(@PathVariable String expressCode){
        return  Result.of(shopInfoExpressService.getUserAccount(expressCode));
    }


}
